package com.cdtu.room.service.impl;

import java.util.Date;
import java.util.List;

import com.cdtu.room.dto.CalendarDto;
import com.cdtu.room.vo.CalendarVo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cdtu.room.mapper.CalendarMapper;
import com.cdtu.room.domain.Calendar;
import com.cdtu.room.service.ICalendarService;

/**
 * 日历Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-03-29
 */
@Service
public class CalendarServiceImpl implements ICalendarService 
{
    @Autowired
    private CalendarMapper calendarMapper;

    /**
     * 查询日历
     * 
     * @param calendarId 日历主键
     * @return 日历
     */
    @Override
    public Calendar selectCalendarByCalendarId(Long calendarId)
    {
        return calendarMapper.selectCalendarByCalendarId(calendarId);
    }

    /**
     * 查询日历列表
     * 
     * @param calendar 日历
     * @return 日历
     */
    @Override
    public List<Calendar> selectCalendarList(Calendar calendar)
    {
        return calendarMapper.selectCalendarList(calendar);
    }

    /**
     * 新增日历
     * 
     * @param calendar 日历
     * @return 结果
     */
    @Override
    public int insertCalendar(Calendar calendar)
    {
        calendar.setFeedbackStatus(1);
        calendar.setCreateBy(SecurityUtils.getUsername());
        calendar.setCreateTime(DateUtils.getNowDate());
        return calendarMapper.insertCalendar(calendar);
    }

    /**
     * 修改日历
     * 
     * @param calendar 日历
     * @return 结果
     */
    @Override
    public int updateCalendar(Calendar calendar)
    {
        calendar.setUpdateTime(DateUtils.getNowDate());
        return calendarMapper.updateCalendar(calendar);
    }

    /**
     * 批量删除日历
     * 
     * @param calendarIds 需要删除的日历主键
     * @return 结果
     */
    @Override
    public int deleteCalendarByCalendarIds(Long[] calendarIds)
    {
        return calendarMapper.deleteCalendarByCalendarIds(calendarIds);
    }

    /**
     * 删除日历信息
     * 
     * @param calendarId 日历主键
     * @return 结果
     */
    @Override
    public int deleteCalendarByCalendarId(Long calendarId)
    {
        return calendarMapper.deleteCalendarByCalendarId(calendarId);
    }

    /**
     * 查询日历列表
     * @param calendarVo
     * @return
     */
    @Override
    public List<CalendarDto> getCalendarList(CalendarVo calendarVo) {
        return calendarMapper.getCalendarList(calendarVo);
    }

    /**
     * 查询已结束的日历条目并更新状态为2
     * @param now
     * @return
     */
    @Override
    public List<CalendarDto> getEndedEvents(Date now) {
        return calendarMapper.getEndedEvents(now);
    }
}
